<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function Phone(brand, price, color) {
        //实例化对象进行初始化
        this.brand = brand;
        this.price = price;
        this.color = color;
      }

      //构造函数的原型对象上声明方法
      Phone.prototype.call = function () {
        console.log("可以打电话..");
      };

      //发送短信
      Phone.prototype.sendMessage = function () {
        console.log("可以发送短信...");
      };

      //声明一个构造函数 智能手机
      function SmartPhone(brand, price, color, pixel, storage, screenSize) {
        //调用父级构造函数
        Phone.call(this, brand, price, color);
        //初始化属性
        this.pixel = pixel;
        this.storage = storage;
        this.screenSize = screenSize;
      }

      //子级构造函数的原型等于父级构造函数的实例
      SmartPhone.prototype = new Phone();
      //调整 constructor
      SmartPhone.prototype.constructor = SmartPhone;

      SmartPhone.prototype.playGame = function(game){
        console.log(`可以玩 ${game} 游戏`);
      }

      //实例化对象
      let IPhone4 = new SmartPhone('苹果', 3500, '白色', '500w', '16G', '3.5inch');

      console.log(IPhone4);  
      IPhone4.call();
      IPhone4.playGame('王者荣耀');
    </script>
  </body>
</html>
